Emacs should work with gcc 5.2 and newer
authorWolfgang Jenkner <wjenkner@inode.at>
Sat, 26 Dec 2015 20:12:02 +0000 (12:12 -0800)
committerRob Browning <rlb@defaultvalue.org>
Mon, 5 Sep 2016 19:33:14 +0000 (14:33 -0500)
This patch, backported from upstream by Aurelien Jarno
<aurel32@debian.org>, has been added:

  Always define gmalloc etc. in src/gmalloc.c

  This is a work-around to prevent the compiler from using semantic
  knowledge about malloc for optimization purposes.  E.g., gcc 5.2
  with -O2 replaces most of calloc's definition by a call to calloc;
  see Bug#22085.
  * src/gmalloc.c [!HYBRID_MALLOC] (malloc, realloc, calloc)
  (aligned_alloc, free): Do not undef.  Instead, define these as
  functions (perhaps renamed to gmalloc etc.) in terms of gmalloc etc.

Origin: backport, commit: 4b1436b702d56eedd27a0777fc7232cdfb7ac4f6
Bug-Debian: http://bugs.debian.org/833727
Added-by: Rob Browning <rlb@defaultvalue.org>
src/gmalloc.c

index cfd39be2bb30ecc2c2f21fa102d40254283940a1..9f93b62df9329362e0d3721bb01fe2cfdb9ab8f8 100644 (file)
@@ -49,6 +49,17 @@ extern "C"
 
 #include <stddef.h>
 
+#undef malloc
+#undef realloc
+#undef calloc
+#undef aligned_alloc
+#undef free
+#define malloc gmalloc
+#define realloc grealloc
+#define calloc gcalloc
+#define aligned_alloc galigned_alloc
+#define free gfree
+#define malloc_info gmalloc_info
 
 /* Allocate SIZE bytes of memory.  */
 extern void *malloc (size_t size);
@@ -1747,6 +1758,42 @@ valloc (size_t size)
   return aligned_alloc (pagesize, size);
 }
 
+#undef malloc
+#undef realloc
+#undef calloc
+#undef aligned_alloc
+#undef free
+
+void *
+malloc (size_t size)
+{
+  return gmalloc (size);
+}
+
+void *
+calloc (size_t nmemb, size_t size)
+{
+  return gcalloc (nmemb, size);
+}
+
+void
+free (void *ptr)
+{
+  gfree (ptr);
+}
+
+void *
+aligned_alloc (size_t alignment, size_t size)
+{
+  return galigned_alloc (alignment, size);
+}
+
+void *
+realloc (void *ptr, size_t size)
+{
+  return grealloc (ptr, size);
+}
+
 #ifdef GC_MCHECK
 
 /* Standard debugging hooks for `malloc'.